use rstest::rstest;

use crate::tests::fixtures::rand_int;
use crate::tiling;

#[rstest]
#[case::valid_slot_1_1_border_tile_no_successor((1, 1), &(-1, 0), false)]
#[case::valid_slot_1_1_none_no_successor((1, 1), &(0, 1), false)]
#[case::valid_slot_2_1_none_no_successor((2, 1), &(1, 0), false)]
#[case::valid_slot_1_1_some_tile_no_successor((1, 1), &(1, 0), false)]
#[case::valid_slot_2_2_some_tile_no_successor((2, 2), &(1, 0), false)]
#[case::valid_slot_2_1_some_tile_successor((2, 1), &(-1, 0), true)]
#[case::valid_slot_2_2_some_tile_successor((2, 2), &(0, -1), true)]
#[case::valid_slot_3_2_some_tile_successor((3, 2), &(-1, 0), true)]
#[case::valid_slot_1_1_some_tile_successor((1, 1), &(2, 1), true)]
#[case::invalid_slot_1_2_no_successor(
    (1, 2),
    &(
        rand_int(-1, 2) as isize,
        rand_int(-1, 2) as isize
    ),
    false,
)]
#[case::invalid_slot_3_1_no_successor(
    (3, 1),
    &(
        rand_int(-1, 2) as isize,
        rand_int(-1, 2) as isize
    ),
    false,
)]
fn test_check_for_successor(
    #[case] current_slot: (usize, usize),
    #[case] offset: &(isize, isize),
    #[case] expected_result: bool,
) {
    let mut slot_grid = tiling::slot_grid::tests::create_test_slot_grid(true, false);
    slot_grid.current_slot = current_slot;

    let result: bool = slot_grid.check_for_successor(offset);

    assert_eq!(result, expected_result);
}
